﻿using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Activation;
using VXCompany.SilverlightLogging.Services.ServiceContracts;
using VXCompany.SilverlightLogging.Services.Business;
using VXCompany.SilverlightLogging.Services.Exceptions;

namespace VXCompany.SilverlightLogging.Services
{
#if DEBUG
	[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
#endif //DEBUG
	[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
	public class LoggingService : ILoggingService
	{
		/// <summary>
		/// Adds the list of exceptions to local log store. Returns success.
		/// </summary>						
		public void LogExceptionBatch(List<ExceptionMessage> messages)
		{
			try
			{
				new LoggingProvider().LogExceptionBatch(messages);				
			}
			catch (ValidationException ex)
			{
				ExceptionPolicy.Current.HandleException(ex);
				throw;
			}
			catch (Exception ex)
			{
				ExceptionPolicy.Current.HandleException(ex);
			}
		}



		/// <summary>
		/// Gets configuration info for silverlight clients.
		/// </summary>
		/// <returns></returns>
		public LoggingConfigurationMessage GetClientConfig()
		{
			LoggingConfigurationMessage config = null;
			try
			{
				config = new LoggingProvider().GetClientConfig();
			}
			catch (Exceptions.ValidationException ex)
			{
				ExceptionPolicy.Current.HandleException(ex);
				throw;
			}
			catch (Exception ex)
			{
				ExceptionPolicy.Current.HandleException(ex);
			}
			return config;
		}
	}
}

